package com.example.trb.controller.performance;

import com.example.trb.dto.ObjectDTO;
import com.example.trb.entity.PerformanceAward;
import com.example.trb.entity.group.Insert;
import com.example.trb.entity.group.Update;
import com.example.trb.service.performance.PerformanceAwardService;
import com.example.trb.util.result.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
public class PerformanceAwardController {
    @Autowired
    PerformanceAwardService paService;
    @Value("${session_user}")
    String userKey;

    @PutMapping("/performanceaward")
    public CommonResult putPerformanceAward(@RequestBody @Validated(Update.class) PerformanceAward data) {
        paService.update(data);
        return CommonResult.success(null);
    }

    @DeleteMapping("/performanceaward")
    public CommonResult deletePerformanceAward(@RequestBody PerformanceAward data) {
        paService.removeById(data.getId());
        return CommonResult.success(null);
    }


    @PostMapping("/performanceaward/status")
    public CommonResult status(@RequestParam("id") Integer id,@RequestParam("status") String status)  {
        paService.updateStatusById(id,status);
        return CommonResult.success(null);
    }

    @GetMapping("/performanceaward")
    public CommonResult getPerformanceAward(@RequestParam("id") Integer id) {
        ObjectDTO dto = paService.getById(id);
        return CommonResult.success(dto.getData());
    }

    @PostMapping("/performanceaward")
    public CommonResult addPerformanceAward(@RequestBody @Validated(Insert.class) PerformanceAward data) {
        ObjectDTO dto = paService.save(data);
        return CommonResult.success(dto.getData());
    }
}
